<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.qijia.travel.app.*"  %>
<%@ page import="com.qijia.travel.domain.*"  %>
<%@ page import="com.qijia.travel.vo.*"  %>
<%@ page import="com.qijia.travel.common.*"  %>
<%@ page import="java.math.*"  %>
<%@page import="com.qijia.travel.helper.ObjectHelper"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

request.setCharacterEncoding("UTF-8");
TouristManager manager = new TouristManager();
EptManager eptManager = new EptManager();
StatisticsVo vo = (StatisticsVo)ObjectHelper.ConvertURLRequsetMapToObj(request.getParameterMap(),StatisticsVo.class);
PageResult pageObj = manager.selectStatisticsForPage(vo);
RewardProfit rewardProfit = manager.getRewardProfitByStatistics(vo);
BigDecimal personGetTotal = new BigDecimal(0);
BigDecimal groupJun = new BigDecimal(0);
boolean showAll = true;
if(vo.getSearchCode()!=null && Constants.SEARCH_GUIDE_TYPE_CODE == vo.getSearchCode()&&"2".equals(vo.getSearchKeyword())){
showAll=false;
}
try{ 
 groupJun=rewardProfit.getProfitTotal().multiply(rewardProfit.getProfitTotalPercent()).divide(new BigDecimal(rewardProfit.getTotalGroupNum()),BigDecimal.ROUND_HALF_EVEN).setScale(2, BigDecimal.ROUND_HALF_UP);
  }catch(Exception e){
  e.printStackTrace();
 }
if(rewardProfit==null)out.println("<script>alert('获取统计数据出错');window.close();window.parent.location.reload();</script>");
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
response.setHeader("Content-disposition","attachment;filename=statistics("+vo.getStDate()+"-"+vo.getEdDate()+").xls"); 
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'statisticsImport.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
                            
 <table cellspacing="0" cellpadding="0" border=1 width=100%>
  <tr >
								<th width="5%" bgcolor="#FFFF00">项次</th><!--从0开始算至第10项，所以性别从第11项开始算-->
								<th width="10%" bgcolor="#FFFF00" nowrap=nowrap>导游编号</th>
								<th width="15%" bgcolor="#FFFF00">导游姓名</th>
								<th width="5%" bgcolor="#FFFF00" nowrap=nowrap>导游类型</th>
								<th width="5%" bgcolor="#FFFF00" nowrap=nowrap>团数</th>
								<th width="20%" bgcolor="#FFFF00" nowrap=nowrap>创利总计(元)</th>
								<th width="20%" bgcolor="#FFFF00" nowrap=nowrap>奖励总计(元)</th>
								<th width="30%" bgcolor="#FFFF00" nowrap=nowrap>个人应得(元)</th>
  </tr>
  <%
  int i=0;
  for(Object obj : pageObj.getPageList()){
	 i++;
	 StatisticsPojo statistic = (StatisticsPojo)obj;
  %>
                               <tr class='<%=i%2==0?"list1":"list2"%>'>
								<td class="tdCheckbox">
								  <%=i%>
								</td>
								<td ><%=statistic.getGuideId()%></td>
								<td ><%=statistic.getGuideName()%></td>
								<td ><%=statistic.getGuideType()==null?"":statistic.getGuideType()+"线"%></td>
								<td ><%=statistic.getGroupNum()%>个</td>
								<td ><%=statistic.getProfitTotal()==null?"":statistic.getProfitTotal().setScale(2,BigDecimal.ROUND_HALF_UP)%></td>
								<td ><%=statistic.getRewardTotal()==null?"":statistic.getRewardTotal().setScale(2,BigDecimal.ROUND_HALF_UP)%></td>
								<td >
								  <%
								     if(statistic.getGuideType()!=null){
								         if(statistic.getGuideType()==1){
								             RewardCounter counter = new FirstGuideTypeCounter();
								             BigDecimal perReward = counter.countReward(statistic,rewardProfit).setScale(2,BigDecimal.ROUND_HALF_UP);
								             if(perReward==null)
								               out.print("<font color='#ff8000'>0.00</font>");
								             else if(perReward.compareTo(new BigDecimal(6000))>0){
								               out.print("<font color='green'>"+perReward+"</font>");
								               personGetTotal = personGetTotal.add(perReward);
								             }else{ 
								               personGetTotal = personGetTotal.add(perReward);
								               out.print("<font color='red'>"+perReward+"</font>");
								               }
								         }else{
								             RewardCounter counter = new SecondGuideTypeCounter();
								             BigDecimal perReward = counter.countReward(statistic,rewardProfit).setScale(2,BigDecimal.ROUND_HALF_UP);
								             if(perReward==null)
								               out.print("<font color='#ff8000'>0.00</font>");
								             else if(perReward.compareTo(new BigDecimal(6000))>0){
								               personGetTotal = personGetTotal.add(perReward);
								               out.print("<font color='green'>"+perReward+"</font>");
								             }else{
								               personGetTotal = personGetTotal.add(perReward);
								               out.print("<font color='red'>"+perReward+"</font>");
								             }
								         }
								      
								     }
								   %>
							    </td>
							</tr>
  <%} %>
  <tr class="<%=i%2==0?"list2":"list1"%>" >
								<td nowrap=nowrap align="right" colspan="8">
								   <b>总计:</b>
								   <%if(showAll){ %>
								   团均：<font style="FONT-SIZE: 16pt; FILTER: wave(add=0,lightstrength=50,strength=3,freq=2,phrase=10); WIDTH: 100%; COLOR: green; LINE-HEIGHT: 100%; FONT-FAMILY: 华文行楷"><%=groupJun%></font>&nbsp;&nbsp;&nbsp;&nbsp;  
								   总团数：<font style="FONT-SIZE: 16pt; FILTER: wave(add=0,lightstrength=50,strength=3,freq=2,phrase=10); WIDTH: 100%; LINE-HEIGHT: 100%; FONT-FAMILY: 华文行楷"><%=rewardProfit.getTotalGroupNum()==null?"":rewardProfit.getTotalGroupNum()%></font>&nbsp;&nbsp;&nbsp;&nbsp;  
								   <% } %>
								   创利总计:<font style="FONT-SIZE: 16pt; FILTER: wave(add=0,lightstrength=50,strength=3,freq=2,phrase=10); WIDTH: 100%; COLOR: green; LINE-HEIGHT: 100%; FONT-FAMILY: 华文行楷"><%=rewardProfit.getProfitTotal()==null?"":rewardProfit.getProfitTotal().setScale(2,BigDecimal.ROUND_HALF_UP)%> </font>&nbsp;&nbsp;&nbsp;&nbsp;  
								   奖励总计:<font style="FONT-SIZE: 16pt; FILTER: wave(add=0,lightstrength=50,strength=3,freq=2,phrase=10); WIDTH: 100%; COLOR: green; LINE-HEIGHT: 100%; FONT-FAMILY: 华文行楷"><%=rewardProfit.getRewardTotal()==null?"":rewardProfit.getRewardTotal().setScale(2,BigDecimal.ROUND_HALF_UP)%></font>&nbsp;&nbsp;&nbsp;&nbsp; 
								   应得总计：<font style="FONT-SIZE: 16pt; FILTER: wave(add=0,lightstrength=50,strength=3,freq=2,phrase=10); WIDTH: 100%; COLOR: green; LINE-HEIGHT: 100%; FONT-FAMILY: 华文行楷"><%=personGetTotal==null?"":personGetTotal.setScale(2,BigDecimal.ROUND_HALF_UP) %></font>
								</td>
							</tr>
							<tr align="center">
								<td colspan="8"></td>
							</tr>
</table>
  </body>
</html>
